﻿using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common;
using KingsSharp.Common.Data;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CRM.Admin.Services.Service.Customer
{
    /// <summary>
    /// 推广计划
    /// </summary>
    public class PromotionPlanService : ServiceBase, IPromotionPlanService
    {
        private IRepository<PromotionPlan, Guid> PromotionPlanRepository;
        public PromotionPlanService(IRepository<PromotionPlan, Guid> _PromotionPlanRepository) : base(_PromotionPlanRepository.UnitOfWork)
        {
            PromotionPlanRepository = _PromotionPlanRepository;
        }
        public IQueryable<PromotionPlan> PromotionPlans { get { return PromotionPlanRepository.Entities; } }

        public OperationResult Delete(params Guid[] ids)
        {
            var entitys = PromotionPlanRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a => a.IsDeleted = true);
            int result = PromotionPlanRepository.Update(entitys.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }

        public OperationResult Insert(params PromotionPlanDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = PromotionPlanRepository.Insert(dtos);
            return result;
        }

        public OperationResult Update(params PromotionPlanDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = PromotionPlanRepository.Update(dtos);
            return result;
        }
    }
}
